import { cloudService } from './index'
import { IStatsChart } from 'vue3-common/types'
import { IJournal, IJournalQuery } from '@/types/journal.ts'

export const addJournalApi = (journal: IJournal): Promise<boolean> =>
  cloudService({
    url: '/home-api/journal',
    method: 'post',
    data: journal
  })

export const updateJournalApi = (id: number, journal: IJournal): Promise<boolean> =>
  cloudService({
    url: `/home-api/journal/${id}`,
    method: 'put',
    data: journal
  })

export const deleteJournalApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/home-api/journal/${id}`,
    method: 'delete'
  })

export const queryJournalApi = (query: IJournalQuery): Promise<IJournal[]> =>
  cloudService({
    url: '/home-api/journal',
    method: 'get',
    params: { ...query }
  })

export const queryJournalCategoryApi = (): Promise<IStatsChart[]> =>
  cloudService({
    url: '/home-api/journal/category',
    method: 'get'
  })
